package com.sjy.pickphotos.pickphotos.util;

import android.app.Application;

import java.lang.reflect.InvocationTargetException;

/**
 * @Author liuyanqi
 * @Date 2021/8/19 0019 上午 11:17
 */
public class AppContext {
    public static Application app;

    public static Application getApp() {
        if (app == null) {
            try {
                app = (Application) Class.forName("android.app.ActivityThread")
                        .getMethod("currentApplication")
                        .invoke(null);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }

        return app;
    }
}
